﻿using System;
using System.Data;
using System.Text;
using UDS.Components;

namespace UDS.Entity
{
    public class MailAttachmentInfo
    {
        public int ID
        {
            get;
            set;
        }

        public int MailBodyID
        {
            get;
            set;
        }

        public string FileName
        {
            get;
            set;
        }

        public int FileSize
        {
            get;
            set;
        }

        public int FileAttribute
        {
            get;
            set;
        }

        /// <summary>
        /// The virtual path of this attachment file.
        /// </summary>
        public string VirtualPath
        {
            get;
            set;
        }

        public string ResolvedVPath
        {
            get
            {
                if (!string.IsNullOrEmpty(VirtualPath))
                {
                    return HttpUtil.ResolveUrl(VirtualPath);
                }
                return string.Empty;
            }
        }

        public DateTime TimeCreated
        {
            get;
            set;
        }

        internal static MailAttachmentInfo ReadAttachmentInfo(IDataReader dr)
        {
            MailAttachmentInfo m = new MailAttachmentInfo();
            m.ID = (int)dr["FileID"];
            m.MailBodyID = (int)dr["MailBodyID"];
            m.FileName = Convert.ToString(dr["FileName"]);
            m.FileSize = (int)dr["FileSize"];
            m.FileAttribute = (int)dr["FileAttribute"];
            m.VirtualPath = Convert.ToString(dr["VirtualPath"]);
            m.TimeCreated = SQLUtil.ReadDataTime(dr["TimeCreated"], DateTime.MinValue);

            return m;
        }
    }
}
